// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Order.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using System;

    using Org.OpenTrader.Framework.Forge.Enums;
    using Org.OpenTrader.Framework.Forge.Interfaces;

    #endregion

    /// <summary>
    /// The order.
    /// </summary>
    [Serializable]
    public class Order : IOrder
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Order"/> class.
        /// </summary>
        /// <param name="providerId">
        /// The providerId.
        /// </param>
        /// <param name="instrumentID">
        /// The instrumentID.
        /// </param>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <param name="way">
        /// The way.
        /// </param>
        /// <param name="price">
        /// The price.
        /// </param>
        /// <param name="quantity">
        /// The quantity.
        /// </param>
        /// <param name="bookingPath">
        /// The bookingPath.
        /// </param>
        public Order(Guid providerId, Guid instrumentID, EOrderType type, EOrderWay way, double price, int quantity, string bookingPath)
        {
            this.OrderProviderID = providerId;
            this.ID = Guid.NewGuid();
            this.BookingPath = bookingPath;
            this.InstrumentID = instrumentID;
            this.Way = way;
            this.Type = type;
            this.Price = price;
            this.Quantity = quantity;
            this.Stamp = Timings.Now;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets BookingPath.
        /// </summary>
        public string BookingPath { get; set; }

        /// <summary>
        /// Gets or sets ID.
        /// </summary>
        public Guid ID { get; set; }

        /// <summary>
        /// Gets or sets InstrumentID.
        /// </summary>
        public Guid InstrumentID { get; set; }

        /// <summary>
        /// Check if the order is valid
        /// </summary>
        public bool IsValid
        {
            get
            {
                if (this.Quantity <= 0)
                {
                    return false;
                }

                if (this.Price < Constants.Zero)
                {
                    return false;
                }

                if (this.Way == 0)
                {
                    return false;
                }

                if (this.Type == 0)
                {
                    return false;
                }

                if (this.BookingPath.Length == 0)
                {
                    return false;
                }

                return true;
            }
        }

        /// <summary>
        /// Gets OrderProviderID.
        /// </summary>
        public Guid OrderProviderID { get; private set; }

        /// <summary>
        /// Gets or sets Price.
        /// </summary>
        public double Price { get; set; }

        /// <summary>
        /// Gets or sets Quantity.
        /// </summary>
        public int Quantity { get; set; }

        /// <summary>
        /// Gets Stamp.
        /// </summary>
        public DateTime Stamp { get; private set; }

        /// <summary>
        /// Gets or sets Type.
        /// </summary>
        public EOrderType Type { get; set; }

        /// <summary>
        /// Gets or sets Way.
        /// </summary>
        public EOrderWay Way { get; set; }

        #endregion
    }
}